package com.glut.library.controller;

import com.glut.library.entity.Book;
import com.glut.library.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * 学生端书籍列表控制器
 * @author stubborn
 * @since 2024-12-13 16:28
 */

@RestController
@RequestMapping("/books")
public class BookController {

    @Autowired
    private IBookService bookService;

    // 获取所有书籍
    @GetMapping("/all")
    public List<Book> getAllBooks() {
        return bookService.getAllBooks(); // 直接返回所有书籍
    }

    // 搜索书籍
    @GetMapping("/search")
    public List<Book> searchBooks(@RequestParam(required = false) String query) {
        return bookService.searchBooks(query); // 直接返回搜索结果
    }
}